﻿using System;
using System.Collections;
namespace test
{
    public class Test
    {
        ArrayList a = new ArrayList();
        public void suShu()
        {
            a.Add(2);
            a.Add(3);
            a.Add(5);
            a.Add(7);
            for (int i = 6; i <= 100; i++)  //将素数放入数组
            {
                if (i == 1 || i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0) continue;
                else
                {
                    bool isSuShu = true;
                    for (int j = 11; j < (i - 1 / 2); j++)
                    {
                        if (i % j == 0) isSuShu = false;
                    }
                    if (isSuShu)
                    {
                        a.Add(i);
                    }
                }
            }
            ArrayList b = a;
            for (int i = 6; i <= 100; i += 2) //输出i为两个素数之和
            {
                int num = 0;
                foreach (int x in a)
                {
                    if (x < i) num++;
                }
                for (int j = 0; j < (num + 1) / 2; j++)  //避免相同两个数组交换位置后重复出现
                {
                    bool ifBigger = false;
                    for (int k = 0; k < b.Count; k++)
                    {
                        int sum = (int)a[j] + (int)b[k];
                        if (sum < i) continue;
                        if (sum > i)
                        {
                            ifBigger = true;
                            break;
                        }
                        if (sum == i)
                        {
                            Console.WriteLine(i + " = " + (int)a[j] + " + " + (int)b[k]);
                            ifBigger = true;
                            break;
                        }
                        if (ifBigger)
                        {
                            break;
                        }
                    }
                }
            }
        }
        public static void Main()
        {
            Test test = new Test();
            test.suShu();
        }
    }
}
